package com.bank.common.commonUtil;

import com.bank.common.stringUtil.JwtUtils;

import javax.servlet.http.HttpServletRequest;

//获取当前用户信息工具类
public class AuthContextHolderUtil {

    //获取当前用户id
    public static Long getUserId(HttpServletRequest request) {

        //jwt从token获取userid
        Long userId = Long.parseLong(JwtUtils.getUserInfo(request.getHeader("Authorization")).get("userId").toString());
        return userId;
    }

    //获取当前用户名称
    public static String getUserName(HttpServletRequest request) {

        //jwt从token获取userid
        String userName = (String) JwtUtils.getUserInfo(request.getHeader("Authorization")).get("userName");
        return userName;
    }


    //获取当前用户手机号
    public static String getUserPhoneNumber(HttpServletRequest request) {

        //jwt从token获取userid
        String phoneNumber = (String)JwtUtils.getUserInfo(request.getHeader("Authorization")).get("phoneNumber");
        return phoneNumber;
    }


    //获取当前用户身份
    public static String getUserRole(HttpServletRequest request) {

        //jwt从token获取userid
        String role = (String)JwtUtils.getUserInfo(request.getHeader("Authorization")).get("role");
        return role;
    }

    //获取token值
    public static String getToken(HttpServletRequest request){
        String token = request.getHeader("Authorization").toString();
        return token;
    }


    //获取当前用户登录状态
    public static String getUserState(HttpServletRequest request) {

        //jwt从token获取userid
        String state = (String)JwtUtils.getUserInfo(request.getHeader("Authorization")).get("state");
        return state;
    }
}